<template>
  <a-spin :spinning="confirmLoading">
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery1">
          <a-row :gutter="24">
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label="手机号">
                <a-input v-model="queryParam.mobile" allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="发送日期">
                <a-range-picker
                  :ranges="{ 今天: [moment(), moment()], 近7天:[moment().subtract(7, 'days'),moment()],本月: [moment().startOf('month'), moment().endOf('month')] }"
                  v-model="deliverDateRange" @change="handleDeliverChange" />
              </a-form-item>
            </a-col>
            <a-col :xl="3" :lg="7" :md="8" :sm="24">
              <a-form-item label="触发事件">
                <a-select v-model="queryParam.tplCate" allowClear>
                  <a-select-option v-for="(item, index) in tplCate" :key="index" :value="item.value">
                    {{ item.text }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery1" icon="search">查询</a-button>
                <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <!-- 操作按钮区域 -->
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <span class="sum">
          短信发送条数
          <span class="b">{{ipagination.total}}</span>
        </span>
      </div>
      <!-- table区域-begin -->
      <div>
        <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
          :pagination="ipagination" :loading="loading" class="j-table-force-nowrap" @change="handleTableChange">
          <span slot="sendStatus" slot-scope="text">
            <a-tag color="blue" v-if="text === 1">成功</a-tag>
            <a-tag color="red" v-if="text === -1">失败</a-tag>
            <a-tag color="orange" v-if="text === 0">待发送</a-tag>
          </span>
        </a-table>
      </div>
      <!-- table区域-end -->
      <!-- 表单区域 -->
    </a-card>
  </a-spin>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import moment from 'moment'

export default {
  name: 'NoteSendList',
  mixins: [JeecgListMixin],
  components: {},
  data() {
    return {
      description: '短信发送记录',
      confirmLoading: false,
      model: {},
      querySum: 0,
      deliverDateRange: [],
      moment,
      // 表头
      columns: [
        {
          title: '发送状态',
          align: 'center',
          dataIndex: 'sendStatus',
          scopedSlots: { customRender: 'sendStatus' },

        },
        {
          title: '触发事件',
          align: 'center',
          dataIndex: 'tplCate',
        },
        {
          title: '门店',
          align: 'center',
          dataIndex: 'shopName',
        },
        {
          title: '手机号',
          align: 'center',
          dataIndex: 'mobile',
        },
        {
          title: '发送内容',
          align: 'center',
          dataIndex: 'sendText',
        },
        {
          title: '发送时间',
          align: 'center',
          dataIndex: 'sendDate',
        },
        {
          title: '操作人',
          align: 'center',
          dataIndex: 'operUserName',
        }
      ],
      tplCate: [
        { text: '生日有礼', value: '生日有礼' },
        { text: '定向赠券', value: '定向赠券' },
      ],

      url: {
        list: '/message/setting/sendNoteList',
      }
    }
  },
  computed: {},
  created() {
  },
  methods: {
    beforeCreate() {
      //加载数据之前处理
      console.log('----beforeCreate---')

      this.$set(this.queryParam, 'tplType', 'SMS')

    },
    searchQuery1() {
      this.loadData(1)
    },
    searchReset1() {
      this.queryParam = {}
      this.deliverDateRange = []
      this.searchQuery1()
    },
    handleDeliverChange(date, dateString) {
      this.queryParam.beganTime = dateString[0]
      this.queryParam.endTime = dateString[1]
    },
  }
}
</script>
<style scoped lang="less">
.sum {
  margin-right: 24px;

  .b {
    font-weight: 600;
    color: @primary-color;
  }
}

@import '~@assets/less/common.less';
</style>